#ifndef __SOCKET_SERVER_H__
#define __SOCKET_SERVER_H__
#ifdef __cplusplus
extern "C" {
#endif


#include <sys/socket.h>
#include <netinet/in.h>

#define MAX_EVENT_NUMBER 1024
#define TCP_CLIENT_MAX   64

typedef void (*TcpConnectCallback)(int fd, struct sockaddr_in* addr);
typedef void (*TcpDisconnectCallback)(int fd);
typedef void (*TcpDataCallback)(int fd, const unsigned char* data, int len);
typedef void (*UdpDataCallback)(int fd,struct sockaddr_in* addr, const unsigned char* data, int len);

typedef struct {
    int running;
    const char* ip;
    int port;

    int enable_tcp;
    int enable_udp;

    int enable_reuse_port;
    int enable_udp_broadcast;

    int recv_timeout_sec;
    int recv_timeout_ms;

    char * bind_to_interface;

    //unsigned char *buf_for_send;
    unsigned char *buf_for_recv_tcp;
    int            buf_for_recv_tcp_size;
    unsigned char *buf_for_recv_udp;
    int            buf_for_recv_udp_size;

    //unsigned int tcp_clients_cnt;
    //int tcp_clients[TCP_CLIENT_MAX];

    TcpConnectCallback on_tcp_connect;
    TcpDisconnectCallback on_tcp_disconnect;
    TcpDataCallback on_tcp_data;
    UdpDataCallback on_udp_data;
} socket_server_config;

int socket_server_exec(socket_server_config *config);

#ifdef __cplusplus
}
#endif

#endif/*__SOCKET_SERVER_H__*/
